using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using NTTHAO.Common;
using NTTHAO.Web.BL.Product;
using NTTHAO.CommonWeb;

public partial class admin_webparts_Plug_ins_Product_ProductTypeViewer : System.Web.UI.UserControl
{
    public bool _IsAdminLogged = false;
    public ProductType _Type = null;
    public ProductTypeConfig _Config = null;
    public DataTable _Products = null;
    public int _PageNo = 1;
    public int _PageCount = 1;
    public long _TotalItem = 0;
    public static int PAGE_SIZE = Constant.NUM_ROW_PER_PAGE;
    public Hashtable _Currency = null;
    public string _ProductUploadeFolder = "../" + Constant.UPLOAD_FILE_PATH;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            this._IsAdminLogged = "admin".Equals(Context.User.Identity.Name, StringComparison.OrdinalIgnoreCase);

            _Currency = new Hashtable();

            DataSet dsCurrency = Currency.GetAll();
            if (dsCurrency != null && dsCurrency.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsCurrency.Tables[0].Rows.Count; i++)
                {
                    DataRow row = dsCurrency.Tables[0].Rows[i];
                    _Currency.Add(row[Currency.ID__COLUMN_NAME], row[Currency.NAME__COLUMN_NAME]);
                }
            }

            int typeID = 0;
            try
            {
                typeID = Int32.Parse(Request.QueryString["typeid"].Trim());
                if (Request.QueryString["p"] != null)
                {
                    this._PageNo = Int32.Parse(Request.QueryString["p"]);
                }
            }
            catch (Exception)
            {
                return;
            }

            if (typeID > 0)
            {
                this._Type = new ProductType(typeID);
                this._Config = ProductTypeConfig.GetConfigByType(this._Type.GroupID, typeID);

                if (this._Type.ID < 1 || this._Config.ID < 1)
                {
                    this._Type = null;
                    this._Config = null;
                }
                else
                {
                    DataSet ds = Product.GetPageByTypeID(this._Type.ID, this._PageNo, PAGE_SIZE, false);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        this._Products = ds.Tables[0];
                        this._TotalItem = Product.CountByTypeID(this._Type.ID, false);
                        this._PageCount = (int)(this._TotalItem / PAGE_SIZE + (this._TotalItem % PAGE_SIZE != 0 ? 1 : 0));
                    }
                }
            }
        }
        catch (Exception)
        {
        }
    }
}
